define(['jquery'], function($) {
	class LoadHeaderAndFooter {
		constructor() {
			this.loadHeader()
			this.loadFooter()
		}
		loadHeader() {
			$('header').load('/html/include/header.html',()=>{
				this.addListener()
			})
		}
		
		// 加载尾部
		loadFooter() {
			$('footer').load('/html/include/footer.html')
		}
		addListener(){
			$(".dgss").on("keyup",this.searchShow)
			$(".dgss-show").delegate("div","click",this.searchup)
			$(".loca").on("mouseenter",this.choicecs)
			this.amount()
		}
		searchShow(){
			const _val=$(".dgss").val()
			const _retu=`https://suggest.taobao.com/sug?code=utf-8&q=${_val}&callback=?`
			$.getJSON(_retu,function(data){	
				let html=""
				data.result.forEach(function(a){
					html+=`<div>${a[0]}</div>`
				})
				// console.log(html)
				$(".dgss-show").html(html)
			})			
		}
		searchup(e){
			// console.log($(e.target).html())
			$(".dgss").val($(e.target).html())
			$(".dgss-show").empty()
		}
		choicecs(){
			// console.log("aaa")
			$(".dzxz").slideDown("slow")
			$(".dzxz").on("click","span",function(e){
				// console.log($(".loca .texts"))
				// console.log($(e.target).text())
				const dz=$(e.target).text()
				$(".loca .texts").text(dz)
			})
			$(".loca").on("mouseleave",function(){
				$(".dzxz").slideUp("slow")
			})
		}
		amount(){
			const cart = JSON.parse(localStorage.getItem('cart')) || []
			if(cart==0){
				$(".cartamount").text(0)
			}else{
				let s=0
				cart.forEach(function(a){
					s+=a.amount
				})
				$(".cartamount").text(s)
			}
		}
	}
	return new LoadHeaderAndFooter()
})
